package com.xgz.service.transaction;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

/**
 * 测试事务
 * @author xgz
 */

@Component
public class UserService {

	@Autowired
	private JdbcTemplate jdbcTemplate;

	@Autowired
	private OrderService orderService;


	@Transactional(rollbackFor = Exception.class)
	public void test() {
		jdbcTemplate.execute("insert into `x_tag` values (11, 'hello', 0)");
		transactionPropagationTest();
	}

	@Transactional(rollbackFor = Exception.class, propagation = Propagation.NEVER)
	public void transactionPropagationTest(){
		jdbcTemplate.execute("insert into `x_tag` values (15, '事务传播', 1)");
	}

}
